]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
windowMenu: Do actions requiring grab once ungrabbed
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Mon, 27 May 2019 21:16:38 +0000 (16:16 -0500)
committerMarco Trevisan (Treviño) <mail@3v1n0.net>
Wed, 29 May 2019 17:04:26 +0000 (12:04 -0500)
Resizing or moving a window needs starting a keyboard grab. However, if the
action is triggered by a menu entry activation it might not work as we already
have already an active grab on input devices to manage the menu itself.

So, possibly wait maximum 100ms for the current grab operation to be completed
before trying go start a new one.

Needs https://gitlab.gnome.org/GNOME/mutter/merge_requests/596
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/1326

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/557

js/ui/windowMenu.js

index 18bda4057ab60a634a416ffbe90b1f6e2c112a6e..78b307db8eec7b5d7fadda45d3734b7421cfe1d4 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*
 
-const { Meta, St } = imports.gi;
+const { GLib, Meta, St } = imports.gi;
 
 const BoxPointer = imports.ui.boxpointer;
 const Main = imports.ui.main;
@@ -42,13 +42,13 @@ var WindowMenu = class extends PopupMenu.PopupMenu {
             item.setSensitive(false);
 
         item = this.addAction(_("Move"), event => {
-            window.begin_grab_op(Meta.GrabOp.KEYBOARD_MOVING, true, event.get_time());
+            this._grabAction(window, Meta.GrabOp.KEYBOARD_MOVING, event.get_time());
         });
         if (!window.allows_move())
             item.setSensitive(false);
 
         item = this.addAction(_("Resize"), event => {
-            window.begin_grab_op(Meta.GrabOp.KEYBOARD_RESIZING_UNKNOWN, true, event.get_time());
+            this._grabAction(window, Meta.GrabOp.KEYBOARD_RESIZING_UNKNOWN, event.get_time());
         });
         if (!window.allows_resize())
             item.setSensitive(false);
@@ -169,6 +169,26 @@ var WindowMenu = class extends PopupMenu.PopupMenu {
         if (!window.can_close())
             item.setSensitive(false);
     }
+
+    _grabAction(window, grabOp, time) {
+        if (global.display.get_grab_op() == Meta.GrabOp.NONE) {
+            window.begin_grab_op(grabOp, true, time);
+            return;
+        }
+
+        let waitId = 0;
+        let id = global.display.connect('grab-op-end', (display) => {
+            display.disconnect(id);
+            GLib.source_remove(waitId);
+
+            window.begin_grab_op(grabOp, true, time);
+        });
+
+        waitId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 100, () => {
+            global.display.disconnect(id);
+            return GLib.SOURCE_REMOVE;
+        });
+    }
 };
 
 var WindowMenuManager = class {